package logic

import (
	"core/component/logger"
	"core/ini"
	"core/mongo"
)

var logicMongo *mongo.MgoClient // 玩家主数据实例

// 初始化mongodb实例
// url示例1 单节点或复制集:mongodb://myuser:myuser@10.1.1.95:27017/admin
// url示例2 分片集群:mongodb://mole:mole@10.1.26.189:27017,10.1.26.190:27017,10.1.26.192:27017/admin
// func initMongoInstance(logicURL, logicName,  billURL, billName, chatURL, chatName string, poolSize, idx int) error {
func InitMongoInstance(cfg *ini.Config, idx int) error {
	var err error
	logicMongo, err = mongo.NewMgoClient(cfg.Mongo.MongoName, cfg.Mongo.MongoUrl, cfg.Mongo.MongoPoolSize, idx)
	if err != nil {
		logger.Infof("connect Mongo failed")
		return err
	}
	return nil
}

func CloseMongoInstance() {
	logicMongo.Close()
}
